<template>
  <div>

    <el-form>
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary">查询
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="add()">增加
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!--表格内容-->
    <el-table ref="list" :data="tableData" style="width: 100%;margin-bottom: 5px;" border stripe highlight-current-row
      :default-sort="{prop: 'date', order: 'descending'}" @row-click="handleRowClick"
      @select-all="handleCheckedAllAndCheckedNone" @select="handleCheckedAllAndCheckedNone"
      :header-cell-style="{textAlign:'center'}" :cell-style="{textAlign:'center'}">
      <el-table-column type="selection">
      </el-table-column>
      <el-table-column property="name" label="商品名称" >
      </el-table-column>
      <el-table-column property="type" label="商品类型" >
      </el-table-column>
      <el-table-column property="company" label="商品所属">
      </el-table-column>
      <el-table-column property="price" label="价钱">
      </el-table-column>
      <el-table-column property="state" label="发布状态">
      </el-table-column>
      <el-table-column property="date" label="发布时间">
      </el-table-column>
      <el-table-column label="操作" width="300" fixed="right">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-view" type="success" title="预览" size="small" ></el-button>
          <el-button circle icon="el-icon-check" type="success" title="发布" size="small" ></el-button>
          <el-button circle icon="el-icon-edit-outline" type="primary" title="编辑" size="small"
            @click="rowEdit(scope.$index, scope.row)"></el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="下架" size="small"
            @click="rowDel(scope.$index, scope.row, $event);"></el-button>
          <el-button circle icon="el-icon-right" type="warning" title="转拍" size="small" ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40,100]" :page-size="10" :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--编辑-弹出层-->
    <Edit v-if="isShowEditDialog" :isShowEditDialog="isShowEditDialog" @dialogClose="dialogClose"></Edit>
    <Add v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @dialogClose="dialogClose"></Add>
  </div>
</template>
    
<script>
import Edit from "./businessEdit.vue";
import Add from "./businessAdd.vue";
export default {
  name: "my",
  components: {
    Edit,
    Add
  },
  data () {
    return {
      formFileds: {
      },

      tableData: [
        {
          id: 0,
          name: '帕萨特',
          type: '机动车',
          company: '某公司',
          price: 50000,
          state: '已发布',
          date: '2016-05-02',
        },
      ],
      isShowEditDialog: false,
      isShowAddDialog: false
    }
  },
  methods: {
    handleRowClick (row, event, column) {

      // 仅选中当前行
      this.setCurRowChecked(row);
    },
    handleCheckedAllAndCheckedNone (selection) {

      // 当前选中仅一行时操作-（当前表格行高亮）
      1 != selection.length && this.$refs.list.setCurrentRow();
    },
    dialogClose () {

      this.isShowEditDialog = false;
      this.isShowAddDialog = false;
    },
    add(){
      this.isShowAddDialog = true;
    },
    rowEdit (index, row) {
      // //当前选中行
      this.formFileds = row;
      this.isShowEditDialog = true;
    },
    rowDel (index, row, event) {

      // 让当前删除按钮失焦
      event.target.blur();

      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {

        this.tableData.splice(row.id, 1);
        this.$message.success('删除成功');
        return false;
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked (row) {

      this.$refs.list.clearSelection();
      this.$refs.list.toggleRowSelection(row);
    }
  }
}
</script>
    
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
    